Completed
Push — master ( 2281e8...8b163e )
by Justin
01:35
created

Document.js ➔ describe(ꞌDocumentꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 75
rs 9

6 Functions

Rating   Name   Duplication   Size   Complexity  
A Document.js ➔ ... ➔ it(ꞌBuildꞌ) 0 13 1
A Document.js ➔ ... ➔ it(ꞌCreate with mixed dataꞌ) 0 16 1
A Document.js ➔ ... ➔ it(ꞌCreate plainꞌ) 0 4 1
A Document.js ➔ ... ➔ it(ꞌtoJSONꞌ) 0 12 1
A Document.js ➔ ... ➔ it(ꞌCreate with JSONꞌ) 0 16 1
A Document.js ➔ ... ➔ it(ꞌconstructor does not copy instancesꞌ) 0 5 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var assert = require('chai').assert,
2
    GedcomX = require('../');
3
4
describe('Document', function(){
5
  
6
  it('Create plain', function(){
7
    assert.instanceOf(GedcomX.Document(), GedcomX.Document, 'An instance of Document is not returned when calling the constructor with new.');
8
    assert.instanceOf(GedcomX.Document(), GedcomX.Document, 'An instance of Document is not returned when calling the constructor without new.');
9
  });
10
  
11
  it('Create with JSON', function(){
12
    var doc = GedcomX.Document({
13
      type: 'http://gedcomx.org/Abstract',
14
      extracted: false,
15
      textType: 'plain',
16
      text: 'Lots of text',
17
      attribution: {
18
        created: 123456789
19
      }
20
    });
21
    assert.equal(doc.getType(), 'http://gedcomx.org/Abstract');
22
    assert.equal(doc.getExtracted(), false);
23
    assert.equal(doc.getTextType(), 'plain');
24
    assert.equal(doc.getText(), 'Lots of text');
25
    assert.equal(doc.getAttribution().getCreated().getTime(), 123456789);
26
  });
27
  
28
  it('Create with mixed data', function(){
29
    var doc = GedcomX.Document({
30
      type: 'http://gedcomx.org/Abstract',
31
      extracted: false,
32
      textType: 'plain',
33
      text: 'Lots of text',
34
      attribution: GedcomX.Attribution({
35
        created: 123456789
36
      })
37
    });
38
    assert.equal(doc.getType(), 'http://gedcomx.org/Abstract');
39
    assert.equal(doc.getExtracted(), false);
40
    assert.equal(doc.getTextType(), 'plain');
41
    assert.equal(doc.getText(), 'Lots of text');
42
    assert.equal(doc.getAttribution().getCreated().getTime(), 123456789);
43
  });
44
  
45
  it('Build', function(){
46
    var doc = GedcomX.Document()
47
      .setType('http://gedcomx.org/Abstract')
48
      .setExtracted(false)
49
      .setTextType('plain')
50
      .setText('Lots of text')
51
      .setAttribution(GedcomX.Attribution().setCreated(123456789));
52
    assert.equal(doc.getType(), 'http://gedcomx.org/Abstract');
53
    assert.equal(doc.getExtracted(), false);
54
    assert.equal(doc.getTextType(), 'plain');
55
    assert.equal(doc.getText(), 'Lots of text');
56
    assert.equal(doc.getAttribution().getCreated().getTime(), 123456789);
57
  });
58
  
59
  it('toJSON', function(){
60
    var data = {
61
      type: 'http://gedcomx.org/Abstract',
62
      extracted: false,
63
      textType: 'plain',
64
      text: 'Lots of text',
65
      attribution: {
66
        created: 123456789
67
      }
68
    }, doc = GedcomX.Document(data);
69
    assert.deepEqual(doc.toJSON(), data);
70
  });
71
  
72
  it('constructor does not copy instances', function(){
73
    var obj1 = GedcomX.Document();
74
    var obj2 = GedcomX.Document(obj1);
75
    assert.strictEqual(obj1, obj2);
76
  });
77
  
78
});